/**
 *  Copyright (C) <2011> <Sysnet Pioneer Solutions Inc.>
 *  Permission is hereby granted, free of charge, to any person obtaining a copy of
 *  this software and associated documentation files (the "Software"), to deal in
 *  the Software without restriction, including without limitation the rights to
 *  use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
 *  of the Software, and to permit persons to whom the Software is furnished to do
 *  so, subject to the following conditions:
 *  
 *  The above copyright notice and this permission notice shall be included in all
 *  copies or substantial portions of the Software.
 *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 *  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 *  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 *  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 *  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 *  SOFTWARE.
 *  
 */    

/**
 * $.set 
 * contains all of the plugin settings.
 */

var xmb_xhr = null;

$.set = {}
$.debug = {}

var JS = function(file){return "asset/global/js/"+file;}
var jQ = function(file){return "asset/libs/jquery/"+file;}
var less = function(file){return "asset/libs/less/"+file;}
var IMG = function(file){return "asset/global/imgs/"+file;}
var reload = function(){
    $.set.dyna_content.re_req = true;
    $(window).trigger("hashchange")
    $.set.dyna_content.re_req = false;
};

var fn = function(){return undefined;}

fn.prototype = {
    
    "false":function(){return false;}
    ,"true":function(){return true;}
    
}

var func = new fn;

/**
 * IE that doesn't have console object. 
 * Except if a firebug-lite is used.
 */
var console = (console == undefined) ? {log:fn,error:fn,warn:fn} :console;
con = console;

/**
 * include
 * Class that helpul for loading script in the right time.
 * @namespace include.scripts
 * @namespace include.once
 * 
 */
var include = {}
    
    /**
     * include.scripts
     * List of scripts.
     * Combination of key and value.
     * key is the word to be called by the Local UI.
     * value is the url of the script.
     */
    include.scripts = {
        // SP Solutions script
        sp_extend:JS("sps-extend.js")
        ,sp_dyna_content:JS("sps-dyna_content.js")
        ,sp_page:JS("sps-page.js")
        ,sp_ajax_effect:JS("sps-ajax_effect.js")
        ,sp_dom_post:JS("sps-dom_post.js")
        ,sp_plugin:JS("sps-plugin.js")
        ,sp_bind_methods:JS("sps-bind_methods.js")
        ,sp_dom_get:JS("sps-dom_get.js")
        ,sp_boolean_elem:JS("sps-boolean_elem.js")
        ,sp_overload:JS("sps-overload.js")
        ,sp_object:JS("sps-object.js")
        ,sp_form:JS("sps-form.js")
        ,sp_bind_once:JS("sps-bind_once.js")
        
        ,jqBBQ:jQ("jqBBQ/1.2.1/script.js")
        ,jqForm:jQ("jqForm/2.87/script.js")
        ,less:less("1/1/5/script.min.js")
        ,jq_scroll_bar:jQ("thomd-jquery-scroll/jquery.scroll.js")
        ,jq_tiny_scroll_bar:jQ("tiny-scrollbars/jquery.tinyscrollbar.js")
        ,stringify:jQ("stringify/script.js")
        ,nivo_slider:jQ("nivo-slider/jquery.nivo.slider.pack.js")
        ,cycle:jQ("jqCycle/jquery.cycle.all.js")
        ,jqOrgchart:jQ("jqOrgchart/jquery.jOrgChart.js")
        ,condense:jQ("condense/jquery.condense.js")
        ,jqCookie:jQ("jqCookie/jqCookie.gcc.js")
    }
    
    /**
     * include.once
     * The same as include_once in PHP. It does load javascript once. If the same has is called it will be ingored.
     * @param scripts - magic word of the script.
     * @param callback - triggers after the script(s) are loaded.
     * @param context - Any value inserted. Usually context term is use for Object that is being inserted.
     * @param options - Options such as {async:bool}.
     */
    include.once = function(scripts,callback,context,options){
        var that = this, url;
        
        if(typeof(scripts) == "string"){
            url = that.scripts[scripts]
        }
        else if(typeof(scripts) == "object"){
            var x=0, url = [], script;
            
            $.each(scripts,function(){
                if(script = that.scripts[scripts[x]]){
                    
                    url[x] = script;
                    
                }else{
                    
                    url[x] = scripts[x];
                    
                };
                
                x++;
            });
        }
        
        $.requireScript(url, callback, context, options)
        
    }
    
    
    
/**
 * Heavenly Bodies
 * @name Earth - area for html view codes.
 * @name Venus - area for styles.
 * @name Mars - area for scripts.
 */

var earth = ".xmb.earth";